#!/bin/bash
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux 
sed -i 's/^nameserver/nameserver 114.114.114.114/g' /etc/resolv.conf
# 关闭swap分区
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab

# 修改 /etc/sysctl.conf
modprobe br_netfilter
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
sysctl -p
# yum install docker-ce
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
yum install -y yum-utils device-mapper-persistent-data lvm2
yum -y install docker-ce
systemctl start docker

tee /etc/docker/daemon.json <<-'EOF'
{
  "insecure-registries" : ["0.0.0.0/0"],
"registry-mirrors": ["https://5uxy6dks.mirror.aliyuncs.com"], 
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker

# 安装docker-compose
curl -L "https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version


# 安装Harbor仓库
IP=`ip addr | grep 'state UP' -A2 | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`
tar -zxvf harbor-offline-installer-v2.1.0.tgz
cd harbor
mv harbor.yml.tmpl harbor.yml
sed -i "5s/reg.mydomain.com/${IP}/g" harbor.yml
sed -i "13s/^/#/g" harbor.yml
sed -i "15,18s/^/#/g" harbor.yml
./prepare || exit
./install.sh --with-clair || exit
docker-compose ps
echo "请在浏览器通过http://${IP}访问Harbor"